package zcw.com.lib_leet_code;

/**
 * Created by 朱城委 on 2021/7/13.<br><br>
 *
 * 丢失的数字
 */
public class Topic268 {

    public static void main(String[] args) {
        Topic268 instance = new Topic268();

        int[] array = new int[] {3,0,1};
        System.out.println(instance.missingNumber(array));

        array = new int[] {0,1};
        System.out.println(instance.missingNumber(array));

        array = new int[] {9,6,4,2,3,5,7,0,1};
        System.out.println(instance.missingNumber(array));
    }

    public int missingNumber(int[] nums) {
        int result = nums.length;

        for(int i = 0; i < nums.length; i++) {
            result = result ^ i ^ nums[i];
        }

        return result;
    }
}
